package com.bw.zg3.notice.Car1

import android.annotation.SuppressLint
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.bw.base.entity.Car1EntityREsult
import com.bw.base.entity.Car1EntityREsultItem
import com.bw.base.entity.Res
import com.bw.base.net.ApiServer
//para 请求网络的参数值
//type 请求哪个接口
@Suppress("UNUSED_EXPRESSION")
class H1Sure(val apiServer: ApiServer,val para:Any,val type:String):PagingSource<Int,Car1EntityREsultItem>() {
    override fun getRefreshKey(state: PagingState<Int, Car1EntityREsultItem>): Int? {
       return null
    }

    @SuppressLint("SuspiciousIndentation")
    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Car1EntityREsultItem> {
        try {
            var res:Res<Car1EntityREsult>?=null
                if (type=="类型"){
                    res=apiServer.getLX(para.toString())

                }else if (type=="状态"){
                    res=apiServer.getZT(para.toString())
                }else if (type=="区域"){
                    res=apiServer.getCar1(para as Int)
                }
            val i = params.key ?: 0
            val car1 = apiServer.getCar1(1)
            val i1 = if (car1.data.size == 10) i + 1 else null
            return LoadResult.Page(res?.data!!,null,i1)
        }catch (e:Exception){
           return LoadResult.Error(e)
        }

    }
}